﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace dodone
{
    /// <summary>
    /// Interaction logic for CalendarWindow.xaml
    /// </summary>
    public partial class CalendarWindow : UserControl
    {
        private DateTime nDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
		private CalendarMonthPanel MonthPanel = new CalendarMonthPanel();
		private CalendarWeekPanel WeekPanel = new CalendarWeekPanel();
		private CalendarDayPanel DayPanel = new CalendarDayPanel();

        public CalendarWindow()
        {
            InitializeComponent();

			PanelGrid.Children.Add(MonthPanel);
			PanelGrid.Children.Add(WeekPanel);
			PanelGrid.Children.Add(DayPanel);

			MonthPanel.AncestorWindow = this;
			WeekPanel.AncestorWindow = this;
			DayPanel.AncestorWindow = this;

			MonthPanel.prtMonthCal(nDate);
			RefreshDay(nDate);
            btnMonth.IsChecked = true;
        }

		public DateTime selectDate
		{
			get { return nDate; }
		}

        private void BeforeButton_Click(object sender, RoutedEventArgs e)
        {
			if (btnMonth.IsChecked == true)
			{
				RefreshDay(nDate.AddMonths(-1));
				MonthPanel.prtMonthCal(nDate);
			}
			else if (btnWeek.IsChecked == true)
			{
				RefreshDay(nDate.AddDays(-7));
				WeekPanel.prtWeekCal(nDate);
			}
			else
			{
				RefreshDay(nDate.AddDays(-1));
				DayPanel.prtDayCal(nDate);
			}
        }

        private void AfterButton_Click(object sender, RoutedEventArgs e)
        {
            if (btnMonth.IsChecked == true)
            {
				RefreshDay(nDate.AddMonths(1));
				MonthPanel.prtMonthCal(nDate);
            }
            else if (btnWeek.IsChecked == true)
            {	
				RefreshDay(nDate.AddDays(7));
				WeekPanel.prtWeekCal(nDate);
            }
			else
			{
				RefreshDay(nDate.AddDays(1));
				DayPanel.prtDayCal(nDate);
			}
        }

        private void TodayButton_Click(object sender, RoutedEventArgs e)
        {
            nDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

			if (btnMonth.IsChecked == true)
			{
				MonthPanel.prtMonthCal(nDate);
				RefreshDay(nDate);
			}
			else if (btnWeek.IsChecked == true)
			{
				WeekPanel.prtWeekCal(nDate);
				RefreshDay(nDate);
			}
			else
			{
				DayPanel.prtDayCal(nDate);
				RefreshDay(nDate);
			}
        }

		public void RefreshDay(DateTime date)
		{
			nDate = date;
			lblMonth.Content = date.Year.ToString() + "년 " + date.Month.ToString() + "월 " + date.Day.ToString() + "일";
		}

        private void MonthButton_Checked(object sender, RoutedEventArgs e)
        {
            MonthPanel.Visibility = Visibility.Visible;
            WeekPanel.Visibility = Visibility.Collapsed;
            DayPanel.Visibility = Visibility.Collapsed;

			MonthPanel.prtMonthCal(nDate);
			RefreshDay(nDate);
        }

        private void WeekButton_Checked(object sender, RoutedEventArgs e)
        {
            MonthPanel.Visibility = Visibility.Collapsed;
            WeekPanel.Visibility = Visibility.Visible;
            DayPanel.Visibility = Visibility.Collapsed;

			WeekPanel.prtWeekCal(nDate);
			RefreshDay(nDate);
        }

        private void DayButton_Checked(object sender, RoutedEventArgs e)
        {
			MonthPanel.Visibility = Visibility.Collapsed;
			WeekPanel.Visibility = Visibility.Collapsed;
			DayPanel.Visibility = Visibility.Visible;

			DayPanel.prtDayCal(nDate);
			RefreshDay(nDate);
        }
    }
}